package com.cdivtc.management.controller;


import com.cdivtc.management.aspect.Log;
import com.cdivtc.management.pojo.LoginLog;
import com.cdivtc.management.pojo.Result;
import com.cdivtc.management.pojo.SysLog;
import com.cdivtc.management.service.LogSever;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api//log")
public class LogController {
    @Autowired
    private LogSever logSever;

    //用户登录日志
    @RequestMapping("queryByUsernameLogin/{uid}")
    public Result queryByUsernameLogin(@PathVariable("uid") String uid) {
        List<LoginLog> loginLogs = logSever.queryByUsernameLogin(uid);
        return new Result().ok().addData(loginLogs);
    }

    //    用户操作日志
    @RequestMapping("queryByUsernameSys/{uid}")
    public Result queryByUsernameSys(@PathVariable("uid") String uid) {
        List<SysLog> loginLogs = logSever.queryByUsernameSys(uid);
        return new Result().ok().addData(loginLogs);
    }

    //    所用登录日志
    @RequestMapping("queryAllSysLog")
    public Result queryAllSysLog() {
        List<SysLog> loginLogs = logSever.queryAllSysLog();
        return new Result().ok().addData(loginLogs);
    }

    //    所用操作日志
    @RequestMapping("queryAllLogin")
    public Result queryAllLogin() {
        List<LoginLog> loginLogs = logSever.queryAllLogin();

        return new Result().ok().addData(loginLogs);
    }

    //    用户删除单个日志

    @RequestMapping(value = "deleteOneByLoginid/{llid}",method = RequestMethod.DELETE)
    public Result deleteOneByLoginid(@PathVariable("llid") String llid) {
        logSever.deleteOneByLoginid(llid);
        return new Result().ok().addData("删除成功");
    }
    //    用户删除单个操作日志

    @RequestMapping(value = "deleteOneBySysLogid/{llid}",method = RequestMethod.DELETE)
    public Result deleteOneBySysLogid(@PathVariable("llid") String llid) {
        logSever.deleteOneBySysId(llid);
        return new Result().ok().addData("删除成功");
    }

    //    用户删除所有操作日志

    @RequestMapping("deleteOneBySysUsername")
    public Result deleteOneBySysUsername(String uid) {
        logSever.deleteOneBySysUsername(uid);

        return new Result().ok().addData("删除成功");
    }
    //    用户删除所有登录日志

    @RequestMapping("deleteOneByLoginUsername")
    public Result deleteOneByLoginUsername(String llid) {
        logSever.deleteOneByUsername(llid);
        return new Result().ok().addData("删除成功");
    }



}
